package vn.ikame.android.adapter;

import java.util.ArrayList;

import vn.ikame.android.handler.CHandler;
import vn.ikame.android.object.Story;
import vn.ikame.android.truyenf17voz.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

 
public class ListStoryAdapter extends ArrayAdapter<Story>{
    ArrayList<Story> array;
    int resource;
    Context context;
     
    public ListStoryAdapter(Context context, int textViewResourceId,
            ArrayList<Story> objects) {
        super(context, textViewResourceId, objects);
        this.context = context;
        resource = textViewResourceId;
        array = objects;       
    }   
 
//    <font color="red">//Phương thức xác định View mà Adapter hiển thị, ở đây chính là CustomViewGroup
    //Bắt buộc phải Override khi kế thừa từ ArrayAdapter</font>
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
         
        if (view == null) {
            view = new CustomStoryView(getContext());
        }
         
        final Story story = array.get(array.size() - 1 - position);
        
        
 
        if (story != null) {
            TextView content = ((CustomStoryView) view).name;
            TextView author = ((CustomStoryView) view).author;
            
            ImageView ll = ((CustomStoryView) view).image;
            
            if(CHandler.isVozTheme){
            	ll.setImageResource(R.drawable.icon_voz);
            } else {
            	ll.setImageResource(R.drawable.icon_story);
            }
             
            
            content.setText(story.getName());
            author.setText("Tác giả: " + story.getAuthor());
             
        }       
        return view;
    }   
}